<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    var a = [1, 3, 6, 3, 23, 76, 1, 34, 222, 6, 456, 221];
    function bubbleSort(array) {
        // 如果数组的长度为单个元素或者没有，那么不用排序直接返回
      const len = array.length;
      if (len < 2) return array;

      for (let i = 0; i < len; i++) {
        for (let j = 0; j < i; j++) {
          if (array[j] > array[i]) {
            const temp = array[j];
            array[j] = array[i];
            array[i] = temp;
          }
        }
      }
      return array;
    }
    console.log(bubbleSort(a));
  </script>
</html>
